package com.stox.ui.javafx.core.view;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import jfxtras.labs.scene.control.window.CloseIcon;
import jfxtras.labs.scene.control.window.Window;

import com.stox.ui.javafx.core.animation.Transitions;
import com.stox.ui.javafx.core.event.handler.BoundsInLocalPropertyChangeListener;
import com.stox.ui.javafx.core.event.handler.BoundsInParentPropertyChangeListener;

public class View extends Window {

	public View(String title) {
		super(title);
		CloseIcon closeIcon = new CloseIcon(this);
		setCloseTransition(Transitions.getClose(this));
		getRightIcons().add(closeIcon);
		closeIcon.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent arg0) {
				close();
			}
		});
		
		boundsInParentProperty().addListener(new BoundsInParentPropertyChangeListener(this));
		boundsInLocalProperty().addListener(new BoundsInLocalPropertyChangeListener(this));
	}
	
	public void open() {
		Transitions.getOpen(this).play();
		Platform.runLater(new Runnable() {
			@Override
			public void run() {
				autosize();
			}
		});
	}
}
